package com.example.dangerouscargodriver.widget;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.HorizontalScrollView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.dangerouscargodriver.R;
import com.example.dangerouscargodriver.controller.AuthController;
import com.example.dangerouscargodriver.entry.MatchLineInfo;
import com.example.dangerouscargodriver.entry.ResourceInfo;
import com.example.dangerouscargodriver.ui.activity.ResourceDetailActivity;

public class MatchLineInfoView extends LinearLayout implements CompoundButton.OnCheckedChangeListener {

    private static final String TAG = "MatchLineInfoView";
    private TextView mTitleName = null;
    private TextView mRoleGradeTitle = null;
    private TextView mCompanyBelongedTo = null;
    private TextView mRoleGrade = null;
    private Context mContext = null;
    private CheckBox mIsChoose = null;
    private MatchLineInfo mMatchLineInfo = null;
    private onCheckListener mListener = null;
    private LinearLayout mLayoutCompanyBelongedTo = null;

    public interface onCheckListener{
        public void onChecked();
        public void onUnChecked();
    }

    public MatchLineInfoView(Context context, MatchLineInfo info) {
        this(context, null, info);
    }

    public MatchLineInfoView(Context context, AttributeSet attrs, MatchLineInfo info) {
        this(context, attrs, 0, info);
    }

    public MatchLineInfoView(Context context, AttributeSet attrs, int defStyleAttr, MatchLineInfo info) {
        super(context, attrs, defStyleAttr);
        init(context, attrs, info);
    }

    public void init(Context context, AttributeSet attrs, MatchLineInfo info) {
        mContext = context;
        mMatchLineInfo = info;
        View itemLayout = LayoutInflater.from(context).inflate(R.layout.layout_match_line_info_item, this);
        mTitleName = itemLayout.findViewById(R.id.tv_title_name);
        mCompanyBelongedTo = itemLayout.findViewById(R.id.tv_company_belonged_to);
        mRoleGradeTitle = itemLayout.findViewById(R.id.tv_role_grade_title);
        mRoleGrade = itemLayout.findViewById(R.id.tv_role_grade);
        mIsChoose = itemLayout.findViewById(R.id.ck_company_choose);
        mIsChoose.setOnCheckedChangeListener(this);
        mLayoutCompanyBelongedTo = findViewById(R.id.layout_company_belonged_to);

        //执行绑定数据的操作
        mTitleName.setText(info.getTitle_name());
        mCompanyBelongedTo.setText(info.getCompany_name());
        mRoleGrade.setText(info.getGrade() + "分");
        if(info.getCid().equals("0")){
            mRoleGradeTitle.setText("车主评分");
        }
        else{
            mRoleGradeTitle.setText("企业评分");
            mLayoutCompanyBelongedTo.setVisibility(GONE);
        }
    }

    public void addCheckedListener(onCheckListener listener){
        mListener = listener;
    }

    public void bindData(MatchLineInfo info){
        if(info != null){
            mTitleName.setText(info.getTitle_name());
            mCompanyBelongedTo.setText(info.getCompany_name());
            mRoleGrade.setText(info.getGrade() + "分");
            if(info.getCid().equals("0")){
                mRoleGradeTitle.setText("车主评分");
            }
            else{
                mRoleGradeTitle.setText("企业评分");
                mLayoutCompanyBelongedTo.setVisibility(GONE);
            }
        }
    }

    @Override
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        if(isChecked){
            mListener.onChecked();
        }
        else{
            mListener.onUnChecked();
        }
    }
}
